﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Rung.Net.Test
{
    public partial class MainMdiForm : Form
    {
        private Form serverForm;

        public MainMdiForm()
        {
            InitializeComponent();
        }

        private void MainMdiForm_Load(object sender, EventArgs e)
        {
            this.serverForm = new SimpleMainFormS();
            this.serverForm.Show();
        }

        private void MainMdiForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            foreach (var child in this.MdiChildren)
            {
                child.Close();
            }

            if (this.serverForm != null && !this.serverForm.IsDisposed)
            {
                this.serverForm.Close();
            }
        }

        private void 新建Simple客户端ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            for (int i = 1; i <= 4; i++)
            {
                Form childForm = new SimpleMainFormC();
                childForm.MdiParent = this;
                childForm.Text = string.Format("客户端{0}（Simple）", IntToChinese(i));
                childForm.Show();
            }

            LayoutMdi(MdiLayout.TileVertical);
        }

        private void 新建Cache客户端ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form childForm = new CacheMainFormC();
            childForm.MdiParent = this;
            childForm.Text = "客户端（Cache）";
            childForm.Show();

            LayoutMdi(MdiLayout.TileVertical);
        }

        private void 新建Session客户端ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            for (int i = 1; i <= 4; i++)
            {
                Form childForm = new SessionMainFormC();
                childForm.MdiParent = this;
                childForm.Text = string.Format("客户端{0}（Session）", IntToChinese(i));
                childForm.Show();

                LayoutMdi(MdiLayout.TileVertical);
            }
        }

        private void 新建综合客户端ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            for (int i = 1; i <= 4; i++)
            {
                Form childForm = new MainFormC();
                childForm.MdiParent = this;
                childForm.Text = string.Format("客户端{0}（综合）", IntToChinese(i));
                childForm.Show();

                LayoutMdi(MdiLayout.TileVertical);
            }
        }

        #region 【菜单栏 - 窗口】
        private void CascadeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.Cascade);
        }

        private void TileVerticalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileVertical);
        }

        private void TileHorizontalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileHorizontal);
        }

        private void ArrangeIconsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.ArrangeIcons);
        }

        private void CloseAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Form childForm in MdiChildren)
            {
                childForm.Close();
            }
        } 
        #endregion

        private string IntToChinese(int i)
        {
            switch (i)
            {
                case 0:
                    return "零";
                case 1:
                    return "一";
                case 2:
                    return "二";
                case 3:
                    return "三";
                case 4:
                    return "四";
                case 5:
                    return "五";
                //case 0:
                //    return "零";
                //case 1:
                //    return "壹";
                //case 2:
                //    return "贰";
                //case 3:
                //    return "叁";
                //case 4:
                //    return "肆";
                //case 5:
                //    return "伍";
                default :
                    return i.ToString();
            }
        }
    }
}
